package com.abbcc.models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.abbcc.common.CommonConst;
import com.abbcc.service.AdminService;
import com.abbcc.service.BaseService;
import com.abbcc.util.BeansFactory;

@Entity
@Table(name = "p_log")
public class TdLog {
	private int logId;
	private String type;
	private String isAdmin;
	private int userId;
	private int adminId;
	private String name;
	private String ldesc;
	private Date addTime;
	private String ip;
	@Id 
	@Column(name="log_id") 
	public int getLogId() {
		return logId;
	}
	public void setLogId(int logId) {
		this.logId = logId;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getIsAdmin() {
		return isAdmin;
	}
	public void setIsAdmin(String isAdmin) {
		this.isAdmin = isAdmin;
	}
	@Column(name="user_id") 
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	@Column(name="admin_id")
	public int getAdminId() {
		return adminId;
	}
	public void setAdminId(int adminId) {
		this.adminId = adminId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getLdesc() {
		return ldesc;
	}
	public void setLdesc(String ldesc) {
		this.ldesc = ldesc;
	}
	@Column(name="add_time") 
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public String userName(){
	BaseService baseService = (BaseService)BeansFactory.get("baseService");
	TdUser user = (TdUser) baseService.findById(TdUser.class,this.getUserId());
	if(user!=null)
		return user.getName();
	else{
		TdAdmin admin = (TdAdmin) baseService.findById(TdAdmin.class,this.getAdminId());
		return admin.getName();
	}
	}
	public String logType(){
		if(this.getType().equals(CommonConst.LOGDEL))
			return "删除";
		if(this.getType().equals(CommonConst.LOGSAVE))
			return "添加";
		if(this.getType().equals(CommonConst.LOGUPDATE))
			return "修改";
		if(this.getType().equals(CommonConst.LOGLOGIN))
			return "登陆系统";
		if(this.getType().equals(CommonConst.LOGLOGOUT))
			return "退出系统";
		if(this.getType().equals(CommonConst.LOGFIND))
			return "查询";
		return "";
	}
}
